package com.example.lee1.controller;

import com.example.lee1.entity.AdminsEntity;
import com.example.lee1.service.AdminsService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-08-13 16:12:03
 */
@RestController
@RequestMapping("generator/admins")
public class AdminsController {
  @Autowired private AdminsService adminsService;

  /** 列表 */
  @RequestMapping("/list")
  //  @RequiresPermissions("generator:admins:list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = adminsService.queryPage(params);

    return R.ok().put("page", page);
  }

  /** 信息 */
  @RequestMapping("/info/{id}")
  //  @RequiresPermissions("generator:admins:info")
  public R info(@PathVariable("id") Integer id) {
    AdminsEntity admins = adminsService.getById(id);

    return R.ok().put("admins", admins);
  }

  /** 保存 */
  @RequestMapping("/save")
  //  @RequiresPermissions("generator:admins:save")
  public R save(@RequestBody AdminsEntity admins) {
    adminsService.save(admins);

    return R.ok();
  }

  /** 修改 */
  @RequestMapping("/update")
  //  @RequiresPermissions("generator:admins:update")
  public R update(@RequestBody AdminsEntity admins) {
    adminsService.updateById(admins);

    return R.ok();
  }

  /** 删除 */
  @RequestMapping("/delete")
  @RequiresPermissions("generator:admins:delete")
  public R delete(@RequestBody Integer[] ids) {
    adminsService.removeByIds(Arrays.asList(ids));

    return R.ok();
  }
}
